<template>
	<div ref="AppFeedback">
		<el-dialog title="意见与反馈" :visible.sync="dialogFormVisible" :close-on-press-escape="false"
			:close-on-click-modal="false" @closed="afterCloseDialog">
			<el-form :model="appFeedbackForm" ref="appFeedbackForm" label-width="100px">
				<el-form-item label="反馈用户" prop="createUserName">
					{{appFeedbackForm.createUserName}}
				</el-form-item>
				<el-form-item label="反馈时间" prop="createTime">
					{{$util.dateFormat(appFeedbackForm.createTime, 'yyyy-MM-dd HH:mm')}}
				</el-form-item>
				<el-form-item label="状态" prop="status">
					<span v-if="appFeedbackForm.status == '1'">待处理</span>
					<span v-else-if="appFeedbackForm.status == '2'">已处理</span>
					<span v-else>无需处理</span>
				</el-form-item>
				<el-form-item label="反馈内容" prop="content">
					{{appFeedbackForm.content}}
				</el-form-item>
				<el-form-item label="附件" prop="images">
					<el-image v-for="(item, index) in images" :key="index" :src="$util.showImage(item)"
						style="width: 100px; height: 100px"></el-image>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">返回</el-button>
				<el-button v-if="appFeedbackForm.status == '1'" @click="handleFeedback('3')">无需优化</el-button>
				<el-button v-if="appFeedbackForm.status == '1'" type="primary" @click="handleFeedback('2')">优化完成
				</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: "AppFeedback",
		data() {
			return {
				dialogFormVisible: false,
				appFeedbackForm: {
					createUserName: null,
					createTime: null,
					status: null,
					content: null,
					images: null
				},
				statusList: [
					{
						id: "1",
						name: "待处理"
					},
					{
						id: "2",
						name: "已处理"
					},
					{
						id: "3",
						name: "无需处理"
					}
				],
				images: []
			};
		},
		methods: {
			initForm(id) {
				if (id) {
					this.appFeedbackForm.id = id;
					this.$api.post('/appFeedback/getById', {
						id: id
					}).then(response => {
						this.dialogFormVisible = true;
						let appFeedback = response.data;
						this.appFeedbackForm = appFeedback;
						if (this.appFeedbackForm.images) {
							this.images = this.appFeedbackForm.images.split(',');
						}
					});
				}
			},
			handleFeedback(status) {
				this.$confirm("确认要处理此条反馈内容?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning"
				}).then(() => {
					this.$api.post('/appFeedback/update', {
						id: this.appFeedbackForm.id,
						status: status
					}).then(response => {
						if (response.code === "900") {
							this.$message.success(response.message);
							this.dialogFormVisible = false;
							this.$parent.handleSearch();
						} else {
							this.$message.error(response.message);
						}
					});
				}).catch(() => {});
			},
			afterCloseDialog() {
				this.appFeedbackForm = {
					createUserName: null,
					createTime: null,
					status: null,
					content: null,
					images: null
				};
				this.images = [];
			}
		}
	};
</script>
